package restaurant.servlet;

import java.sql.SQLException;
import java.util.List;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import restaurant.pojo.Board;
import restaurant.service.BoardService;
import restaurant.service.impl.BoardServiceImpl;
import restaurant.utils.BaseServlet;

/**
 * Servlet implementation class BaseBoardServlet
 */
@WebServlet("/restaurant/detail/BaseBoardServlet")
public class BaseBoardServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
	private BoardService service = new BoardServiceImpl();
	public String showBoard(HttpServletRequest req,HttpServletResponse resp) {	
		try {
			List<Board> board = service.showBoard();
			req.setAttribute("datas", board);	
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "boardList.jsp";
	}
	public String addBoard(HttpServletRequest req,HttpServletResponse resp) {
		String name = req.getParameter("bName");
		System.out.println(name);
		try {
			service.addBoard(name);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "BaseBoardServlet?action=showBoard";
	}
	public String delBoard(HttpServletRequest req,HttpServletResponse resp) {
		String id = req.getParameter("id");
		try {
			service.delBoard(id);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "BaseBoardServlet?action=showBoard";
	}
	public String orderBoard(HttpServletRequest req,HttpServletResponse resp) {
		String id = req.getParameter("id");
		String state = req.getParameter("state");
		try {
			service.update(id, state);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return "BaseBoardServlet?action=showBoard";
	}
	public String findBoard(HttpServletRequest req,HttpServletResponse resp) {
		String param = req.getParameter("keyword");
		try {
			List<Board> board = service.find(param);
			req.setAttribute("datas", board);
		} catch (SQLException e) {
			
			e.printStackTrace();
		}
		return "boardList.jsp";
	}
}
